﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Top.Web;
using Top.Data;
using Top.PointStore.Business.Models;
namespace Top.PointStore.Business
{
    public class ExternalVisitManager
    {
        //-----------------------------------------数据库操作------------------------------------------------
        public static async Task<int> Insert(string userToken,string ip,string tag,string url,string beforeUrl,string city)
        {
            DateTime time = DateTime.Now;
            #region SQL
            string sql = @"
                    INSERT INTO T_PointStoreVisitLog
                               (
                                F_MessageKey
                               ,F_UserToken
                               ,F_Ip
                               ,F_tag
                               ,F_Url
                               ,F_BeforeUrl
                               ,F_City
                               ,F_VisitYeah
                               ,F_VisitMonth
                               ,F_VisitDay
                               ,F_VisitHour
                               ,F_VisitMinutes
                               ,F_VisitTime)
                         VALUES    
                         (       
                                {0:F_MessageKey}
                               ,{0:F_UserToken}
                               ,{0:F_Ip}
                               ,{0:F_tag}
                               ,{0:F_Url}
                               ,{0:F_BeforeUrl}
                               ,{0:F_City}
                               ,{0:F_VisitYeah}
                               ,{0:F_VisitMonth}
                               ,{0:F_VisitDay}
                               ,{0:F_VisitHour}
                               ,{0:F_VisitMinutes}
                               ,{0:F_VisitTime}
                          );
                    "; 
            #endregion
            T_PointStoreVisitLog visitor = new T_PointStoreVisitLog(){
                F_MessageKey=Guid.NewGuid().ToString(),
                F_UserToken=userToken,
                F_Ip=ip,
                F_tag=tag,
                F_Url=url,
                F_BeforeUrl=beforeUrl,
                F_City=city,
                F_VisitYeah=time.Year,
                F_VisitMonth=time.Month,
                F_VisitDay=time.Day,
                F_VisitHour=time.Hour,
                F_VisitMinutes=time.Minute,
                F_VisitTime=time
            };
            using (var db = new DbTour())
            {
                await db.Sql(sql, visitor).ExecuteNonQuery();
            }
            return 1;
        }
    }
}
